package com.ohos.connect.devicecloud.app.modular.projectdevice.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connect.devicecloud.app.modular.projectdevice.model.dto.ProjectDeviceDeleteDTO;
import com.ohos.connect.devicecloud.app.modular.projectdevice.model.vo.ProjectDeviceListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ohos.connect.devicecloud.common.annotation.CommonLog;
import com.ohos.connect.devicecloud.common.pojo.CommonResult;
import com.ohos.connect.devicecloud.app.modular.projectdevice.model.dto.ProjectDeviceAddDTO;
import com.ohos.connect.devicecloud.app.modular.projectdevice.model.param.ProjectDeviceEditParam;
import com.ohos.connect.devicecloud.app.modular.projectdevice.model.dto.ProjectDeviceSearchDTO;
import com.ohos.connect.devicecloud.app.modular.projectdevice.service.ProjectDeviceService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * APP项目设备控制器
 *
 * @author Dongtao
 * @date  2024/12/05 11:08
 */
@Api(tags = "项目设备接口")
@ApiSupport(author = "Dongtao", order = 2)
@RestController
@RequestMapping(value = "/api/v1/device_cloud/app/projectdevice")
@Validated
public class ProjectDeviceController {

    @Resource
    private ProjectDeviceService projectDeviceService;

    /**
     * 添加APP项目设备
     *
     * @author Dongtao
     * @date  2024/12/05 11:08
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("批量添加项目设备")
    @CommonLog("批量添加项目设备")
    @PostMapping("/add")
    public CommonResult<Boolean> add(@RequestBody @Valid ProjectDeviceAddDTO projectDeviceAddDTO) {
        return CommonResult.data(projectDeviceService.add(projectDeviceAddDTO));
    }

    /**
     * 编辑APP项目设备
     *
     * @author Dongtao
     * @date  2024/12/05 11:08
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "编辑项目设备",hidden = true)
    @CommonLog("编辑项目设备")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid ProjectDeviceEditParam projectDeviceEditParam) {
        projectDeviceService.edit(projectDeviceEditParam);
        return CommonResult.ok();
    }

    /**
     * 批量删除APP项目设备
     *
     * @author Dongtao
     * @date  2024/12/05 11:08
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "批量删除项目设备")
    @CommonLog("批量删除项目设备")
    @PostMapping("/delete")
    public CommonResult<Boolean> delete(@RequestBody @Valid ProjectDeviceDeleteDTO projectDeviceDeleteDTO) {
        return CommonResult.data(projectDeviceService.delete(projectDeviceDeleteDTO));
    }

    /**
     * 获取APP项目设备列表
     *
     * @author Dongtao
     * @date  2024/12/05 11:08
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取项目设备列表")
    @PostMapping("/list")
    public CommonResult<ProjectDeviceListVO> detail(@RequestBody @Valid ProjectDeviceSearchDTO projectDeviceSearchDTO) {
        return CommonResult.data(projectDeviceService.getProjectDeviceList(projectDeviceSearchDTO));
    }


}
